package com.etime.shuhuiyuan.controllers.coursetype;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.pojo.CourseType;
import com.etime.shuhuiyuan.services.coursetype.interfaces.CourseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * demo示例的controller控制层
 */
@Api(tags = "courseType案例接口")
@RestController
@RequestMapping("/courseType")
public class CourseTypeController {

    @Autowired
    private CourseTypeService courseTypeService;


    @ApiOperation("添加courseType案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name="coursetypeid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="coursetypename",value="传递字符串"),
            @ApiImplicitParam(name="coursetypedesc",value="传递字符串"),
            @ApiImplicitParam(name="coursetypestate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="courseptypeid",value="传递数字"),
            @ApiImplicitParam(name="coursetypeicon",value="传递字符串")

    })
    @PostMapping("/insert")
    public BaseMessage insertCourseType(CourseType courseType){
        BaseMessage msg = new BaseMessage();
        int rtn = courseTypeService.insertCourseType(courseType);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseType成功");
        }else{
            msg.setMsg("保存courseType失败");
        }
        return msg;
    }

    @ApiOperation("修改courseType案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="coursetypeid",value = "自增长主键，必须传递"),
            @ApiImplicitParam(name="coursetypename",value="传递字符串"),
            @ApiImplicitParam(name="coursetypedesc",value="传递字符串"),
            @ApiImplicitParam(name="coursetypestate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name="courseptypeid",value="传递数字"),
            @ApiImplicitParam(name="coursetypeicon",value="传递字符串")
    })
    @PostMapping("/update")
    public BaseMessage updateCourseType(CourseType courseType){
        BaseMessage msg = new BaseMessage();
        int rtn = courseTypeService.updateCourseType(courseType);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存courseType成功");
        }else{
            msg.setMsg("保存courseType失败");
        }
        return msg;
    }
    @ApiOperation("查询courseType列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="coursetypename",value="传递字符串"),
            @ApiImplicitParam(name="coursetypestate",value = "状态，0-不可用；1-正常")
    })
    @GetMapping("/list")
    public ListMessage<CourseType> selectCourseTypeList(CourseType courseType){
        ListMessage<CourseType> listMessage = new ListMessage<>();
        List<CourseType> list = courseTypeService.selectCourseTypeList(courseType);
        if(list!=null) {
            listMessage.setDatalist(list);
            listMessage.setCode(1);
        }else{
            listMessage.setCode(0);
            listMessage.setMsg("没有查询到数据");
        }
        return listMessage;
    }

    @ApiOperation("分页查询courseType案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="coursetypename",value="传递字符串"),
            @ApiImplicitParam(name="coursetypestate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<CourseType> selectRoleByPage(CourseType courseType, Long pagenum, Long pagesize){
        Page<CourseType> pagedata = courseTypeService.selectCourseTypeByPage(courseType,pagenum,pagesize);
        PageMessage<CourseType> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据coursetypeid查询一条courseType信息的案例")
    @ApiImplicitParam("coursetypeid")
    @GetMapping("/get/{coursetypeid}")
    public PojoMessage<CourseType> selectCourseTypeById(@PathVariable("coursetypeid") int coursetypeid){
        PojoMessage<CourseType> msg = new PojoMessage<>();
        CourseType courseType = courseTypeService.selectCourseTypeById(coursetypeid);
        if(courseType!=null){
            msg.setCode(1);
            msg.setData(courseType);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }
}

